package com.jsbb.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger配置
 *
 * @author jsbb
 */
@Configuration
public class SwaggerConfig {

    private final String token = "token";

    @Bean
    public OpenAPI customOpenAPI() {
        OpenAPI openapi = new OpenAPI().info(new Info().title("接口文档"));
        openapi.schemaRequirement(token, this.securityScheme());
        openapi.addSecurityItem(new SecurityRequirement().addList(token));
        return openapi;
    }

    private SecurityScheme securityScheme() {
        SecurityScheme securityScheme = new SecurityScheme();
        securityScheme.setType(SecurityScheme.Type.APIKEY);
        securityScheme.setName(token);
        securityScheme.setIn(SecurityScheme.In.HEADER);
        return securityScheme;
    }
}
